package com.yulongtian.interviewWorks.day20220826;


import javax.swing.*;
import java.beans.Visibility;

/**
 * https://leetcode.cn/problems/route-between-nodes-lcci/submissions/
 *
 * @author YulongTian
 * @date 2022/8/26 - 10:02
 */
public class Test02 {
    public static void main(String[] args) {

    }

    //题解
    //定义全局变量，与每次查找结果进行**或**操作
    boolean res = false;
    public boolean findWhetherExistsPath(int n, int[][] graph, int start, int target) {
        return find(graph,start,target);
    }

    public boolean find(int [][]graph, int start, int target){
        //找到后返回true
        if(start == target) return true;
        //遍历graph,找到graph中包含target的所有通路，不断更新target来缩短查找长度
        for(int i = 0 ; i < graph.length ; i++){
            if(graph[i][1] == target && res == false){
                //用**或**操作更新res
                res |= find(graph,start,graph[i][0]);
                //找到一条通路即返回true
            }else if(res){
                return true;
            }
        }
        return res;
    }


}
